/**
 * Copyright (c) 2005 - 2007 FeyaSoft Corp. All Rights Reserved.
 */
package com.feyaSoft.home.web.source;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author Fenqiang Zhuang
 * @Oct 8, 2007
 * 
 * This file is used to .....
 */
public class SourceUtil {

	/**
	 * create JSon response out - for list of account page
	 * 
	 * @param request
	 * @param response
	 * @param tsts
	 * @throws Exception
	 */
	public static void jsonResponse(SourceJson json,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		// check whether it is script Tag...
		// which is called by JSON
		boolean scriptTag = false;
		String cb = request.getParameter("callback");
		if (cb != null) {
			scriptTag = true;
			response.setContentType("text/javascript");
		} else {
			response.setContentType("application/x-json");
		}

		PrintWriter out = response.getWriter();
		if (scriptTag) {
			out.write(cb + "(");
		}
		response.getWriter().print(json.toJSONObject());
		if (scriptTag) {
			out.write(");");
		}
	}
}
